package com.molyfun.parents.im.model;

import android.text.TextUtils;

import com.hyphenate.chat.EMMessage;
import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.rest.BaseResponse;
import com.molyfun.parents.rest.bean.ProductDetailResponse;
import com.molyfun.parents.rest.bean.TeacherDetailResponse;

import java.util.List;

import static com.molyfun.parents.utils.Const.VIDEO_COVER_SUFFIX;

/**
 * Created by ligang on 2017/9/25 0025.
 */

public class ChatMessageEntity extends BaseResponse {
    /**
     * bigurl : http://media.molyfun.com/mf/product/pics/ic_20170629-150232985.jpg?imageMogr2/thumbnail/1280x1280
     * id : 402883e05ea869c9015ea86ca81a0000
     * planId : 691efe6342e647b3aa91aad92715781e
     * userId : e548cebc5df0285e015df453bfd908a5
     * userName : 预约咨询
     * userType : 2
     * headimgurl : 头像  http://media.molyfun.com/helloimg/user/20170907/201709071903384cJQnTjk.jpg?imageMogr2/thumbnail/300x300
     * content :    文字内容
     * url : http://media.molyfun.com/mf/product/pics/ic_20170629-150232985.jpg?imageMogr2/thumbnail/300x300
     * type : 5     记录类型   1:图片 2.视频 3.音频 4.文字 5.套餐  6.评价
     * timelen :    音频时长
     * cover :  视频封面
     * extendfield1 : 8a2d92635ceedfa6015cf2a889640b52  扩展字段1  （type=5时表示套餐Id  ；type=6时表示评价结果  1 满意  2 一般  3 不满意）
     * extendfield2 : 套餐    扩展字段2  套餐标题
     * extendfield3 : 2.00      扩展字段3  价格
     * extendfield4 : 0.10      扩展字段4  折扣价
     * extendfield5 : 2     扩展字段5  售出量
     * extendfield6 : 0     扩展字段6  库存
     * createdatetimeStr : 2017-09-22 15:10:47
     */

    private String bigurl;
    private String id;
    private String customplanid;
    private String userid;
    private String username;
    private String usertype;
    private String headimgurl;
    private String content;
    private String url;
    private String type;
    private String timelen;
    private String cover;
    private String extendfield1;
    private String extendfield2;
    private String extendfield3;
    private String extendfield4;
    private String extendfield5;
    private String extendfield6;
    private String createdatetimeStr;
    private String uid;
    private long createdatetime;
    private boolean isUseNative = false;
    private String conversationId;
    private String fromdev;
    private String imgroupid;
    private List<TeacherDetailResponse.TeacherDetailBean> userlist;

    public String getFromdev() {
        return fromdev;
    }

    public void setFromdev(String fromdev) {
        this.fromdev = fromdev;
    }

    public long getCreatedatetime() {
        return createdatetime;
    }

    public String getConversationId() {
        return conversationId;
    }

    public void setConversationId(String conversationId) {
        this.conversationId = conversationId;
    }

    private NormalFileMessageBody body;
    private ErrorNativeBody errorNativeBody;

    public String getCustomplanid() {
        return customplanid;
    }

    public void setCustomplanid(String customplanid) {
        this.customplanid = customplanid;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsertype() {
        return usertype;
    }

    public void setUsertype(String usertype) {
        this.usertype = usertype;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getBigurl() {
        return bigurl;
    }

    public void setBigurl(String bigurl) {
        this.bigurl = bigurl;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getHeadimgurl() {
        return headimgurl;
    }

    public void setHeadimgurl(String headimgurl) {
        this.headimgurl = headimgurl;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<TeacherDetailResponse.TeacherDetailBean> getUserlist() {
        return userlist;
    }

    public void setUserlist(List<TeacherDetailResponse.TeacherDetailBean> userlist) {
        this.userlist = userlist;
    }

    //    public String getType() {
//        return type;
//    }

    /**
     * 1:图片 2.视频 3.音频 4.文字 5.套餐  6.评价
     * @return
     */
    public String getType() {
//        if(TextUtils.isEmpty(type)){
//            return EMMessage.Type.TXT;
//        }
//        if(type.equals("1")){
//            return  EMMessage.Type.IMAGE;
//        }else if(type.equals("2")){
//            return EMMessage.Type.VIDEO;
//        }else if(type.equals("3")){
//            return EMMessage.Type.VOICE;
//        }else if(type.equals("4")){
//            return EMMessage.Type.TXT;
//        }
//
//        return EMMessage.Type.TXT;
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTimelen() {
        return timelen;
    }

    public void setTimelen(String timelen) {
        this.timelen = timelen;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getExtendfield1() {
        return extendfield1;
    }

    public void setExtendfield1(String extendfield1) {
        this.extendfield1 = extendfield1;
    }

    public String getExtendfield2() {
        return extendfield2;
    }

    public void setExtendfield2(String extendfield2) {
        this.extendfield2 = extendfield2;
    }

    public String getExtendfield3() {
        return extendfield3;
    }

    public void setExtendfield3(String extendfield3) {
        this.extendfield3 = extendfield3;
    }

    public String getExtendfield4() {
        return extendfield4;
    }

    public void setExtendfield4(String extendfield4) {
        this.extendfield4 = extendfield4;
    }

    public String getExtendfield5() {
        return extendfield5;
    }

    public void setExtendfield5(String extendfield5) {
        this.extendfield5 = extendfield5;
    }

    public String getExtendfield6() {
        return extendfield6;
    }

    public void setExtendfield6(String extendfield6) {
        this.extendfield6 = extendfield6;
    }

    public String getCreatedatetimeStr() {
        return createdatetimeStr;
    }

    public void setCreatedatetimeStr(String createdatetimeStr) {
        this.createdatetimeStr = createdatetimeStr;
    }

    public long getMsgTime() {
        return createdatetime;
    }

    public void setCreatedatetime(long createdatetime) {
        this.createdatetime = createdatetime;
    }

    public EMMessage.Direct direct() {
        return userid.equals(MFPApplication.getInstance().getUser().getId()) ? EMMessage.Direct.SEND : EMMessage.Direct.RECEIVE;
    }

    public String getFrom() {
        return username;
    }

    public EMMessage.Status status() {
        EMMessage.Status status = EMMessage.Status.SUCCESS;
        return status;
    }

    public NormalFileMessageBody getBody() {
        if(body == null){
            body = new NormalFileMessageBody();
            if(!TextUtils.isEmpty(timelen)){
                body.setLength(Integer.parseInt(timelen));
            }
            if(type.equals("2")){
                body.setThumbnailUrl(url + VIDEO_COVER_SUFFIX);
            }
            body.setRemoteUrl(url);
        }
        return body;
    }

    public void setBody(NormalFileMessageBody body) {
        this.body = body;
    }

    public boolean isUseNative() {
        return isUseNative;
    }

    public void setUseNative(boolean useNative) {
        isUseNative = useNative;
    }

    public ErrorNativeBody getErrorNativeBody() {
        return errorNativeBody;
    }

    public void setErrorNativeBody(ErrorNativeBody errorNativeBody) {
        this.errorNativeBody = errorNativeBody;
    }

    public String getImgroupid() {
        return imgroupid;
    }

    public void setImgroupid(String imgroupid) {
        this.imgroupid = imgroupid;
    }

    public ProductDetailResponse.ProductDetailBean getProductDetailBean(){
        ProductDetailResponse.ProductDetailBean productDetailBean = new ProductDetailResponse.ProductDetailBean();

        double discountPrice = 0.0;
        String price = getExtendfield4();
        if(!TextUtils.isEmpty(price)){
            discountPrice = Double.valueOf(price.toString());
        }
        double priceNow = 0;
        if(!TextUtils.isEmpty(getExtendfield3().trim())){
            priceNow = Double.parseDouble(getExtendfield3().trim());
        }

        productDetailBean.setId(getExtendfield1());
        productDetailBean.setCreatedatetime(getMsgTime());
        productDetailBean.setDiscountprice(discountPrice);
        productDetailBean.setPrice(priceNow);
        productDetailBean.setName(getExtendfield2());
        return productDetailBean;
    }

    @Override
    public String toString() {

//        private String bigurl;
//        private String id;
//        private String customplanid;
//        private String userid;
//        private String username;
//        private String usertype;
//        private String headimgurl;
//        private String content;
//        private String url;
//        private String type;
//        private String timelen;
//        private String cover;
//        private String extendfield1;
//        private String extendfield2;
//        private String extendfield3;
//        private String extendfield4;
//        private String extendfield5;
//        private String extendfield6;
//        private String createdatetimeStr;
//        private String uid;
//        private long createdatetime;

        StringBuilder sb = new StringBuilder();
        sb.append("bigurl--->" + bigurl);
        sb.append("\nid--->" + id);
        sb.append("\ncustomplanid--->" + customplanid);
        sb.append("\nuserid--->" + userid);
        sb.append("\nusername--->" + username);
        sb.append("\nusertype--->" + usertype);
        sb.append("\nheadimgurl--->" + headimgurl);
        sb.append("\ncontent--->" + content);
        sb.append("\nurl--->" + url);
        sb.append("\ntype--->" + type);
        sb.append("\ntimelen--->" + timelen);
        sb.append("\ncover--->" + cover);
        sb.append("\nextendfield1--->" + extendfield1);
        sb.append("\nextendfield2--->" + extendfield2);
        sb.append("\nextendfield3--->" + extendfield3);
        sb.append("\nextendfield4--->" + extendfield4);
        sb.append("\nextendfield5--->" + extendfield5);
        sb.append("\nextendfield6--->" + extendfield6);
        sb.append("\ncreatedatetimeStr--->" + createdatetimeStr);
        sb.append("\nuid--->" + uid);
        sb.append("\ncreatedatetime--->" + createdatetime);
        sb.append("\nimgroupid--->" + imgroupid);


        return sb.toString();
    }

    public static class ErrorNativeBody{
        private String filePath;
        private int length;
        //只是视频封面
        private String thumbPath;
        //1:图片 2.视频 3.音频 4.文字 5.套餐  6.评价
        private int type;

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public int getLength() {
            return length;
        }

        public void setLength(int length) {
            this.length = length;
        }

        public String getThumbPath() {
            return thumbPath;
        }

        public void setThumbPath(String thumbPath) {
            this.thumbPath = thumbPath;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }
    }
}
